package com.yfp.client.controller;

import com.yfp.client.domain.dto.ClientHealthLogDTO;
import com.yfp.client.domain.vo.*;
import com.yfp.client.service.ClientHealthLogService;
import com.yfp.client.service.ClientHistoryInfoService;
import com.yfp.client.util.Response;
import com.yfp.common.core.web.controller.BaseController;
import com.yfp.client.domain.vo.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/client/nutrition")
@Tag(name = "饮食日记")
public class ClientNutritionController extends BaseController {

    @Resource
    private ClientHealthLogService clientHealthLogService;
    @Resource
    private ClientHistoryInfoService clientHistoryInfoService;


    @GetMapping("/health/statistic")
    @Operation(summary = "热量记录-查询热量记录统计")
    public Response<ClientHealthLogStatisticVO> getClientHealthLogStatistic(@Parameter(name = "startTime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startTime,
                                                                            @Parameter(name = "endTime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime) {
        ClientHealthLogStatisticVO clientHealthLogStatistic = clientHealthLogService.getClientHealthLogStatistic(startTime, endTime);
        return Response.success(clientHealthLogStatistic);
    }

    @GetMapping("/health/list")
    @Operation(summary = "今日记录-查询记录列表")
    public Response<List<ClientHealthLogListVO>> getClientHealthLogList(@Parameter(name = "startTime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startTime,
                                                                        @Parameter(name = "endTime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime) {
        List<ClientHealthLogListVO> clientHealthLogList = clientHealthLogService.getClientHealthLogList(startTime, endTime);
        return Response.success(clientHealthLogList);
    }

    @GetMapping("/health/{id}")
    @Operation(summary = "今日记录-查询记录详情")
    public Response<ClientHealthLogVO> getClientHealthLogById(@PathVariable Long id) {
        ClientHealthLogVO clientHealthLogById = clientHealthLogService.getClientHealthLogById(id);
        return Response.success(clientHealthLogById);
    }

    @PostMapping("/health/estimate")
    @Operation(summary = "今日记录-估重-根据克重计算")
    public Response<ClientHealthLogVO> estimateWeightByGram(@RequestBody ClientHealthLogDTO clientHealthLogDTO) {
        ClientHealthLogVO clientHealthLogById = clientHealthLogService.estimateWeightByGram(clientHealthLogDTO);
        return Response.success(clientHealthLogById);
    }

    @PutMapping("/health/status")
    @Operation(summary = "今日记录-修改记录状态")
    public Response<Void> updateClientHealthLogStatus(@RequestBody ClientHealthLogDTO clientHealthLogDTO) {
        clientHealthLogService.updateClientHealthLogStatus(clientHealthLogDTO);
        return Response.success();
    }

    @PutMapping("/health/weight")
    @Operation(summary = "今日记录-修改记录克重")
    public Response<Void> updateClientHealthLogWeight(@RequestBody ClientHealthLogDTO clientHealthLogDTO) {
        clientHealthLogService.updateClientHealthLogWeight(clientHealthLogDTO);
        return Response.success();
    }

    @GetMapping("/body/list")
    @Operation(summary = "身体数据-查询记录列表")
    public Response<List<ClientHistoryInfoVO>> getClientHistoryInfoList() {
        List<ClientHistoryInfoVO> clientHistoryInfoList = clientHistoryInfoService.getClientHistoryInfoList();
        return Response.success(clientHistoryInfoList);
    }

    @GetMapping("/body")
    @Operation(summary = "身体数据-查询记录详情")
    public Response<ClientHistoryInfoBodyVO> getClientHistoryInfo() {
        ClientHistoryInfoBodyVO clientHistoryInfoBodyVO = clientHistoryInfoService.getClientHistoryInfo();
        return Response.success(clientHistoryInfoBodyVO);
    }

    @GetMapping("/guide/page")
    @Operation(summary = "引导页")
    public Response<ClientHealthGuidePageVO> guidePage() {
        ClientHealthGuidePageVO clientHealthGuidePageVO = clientHistoryInfoService.guidePage();
        return Response.success(clientHealthGuidePageVO);
    }
}
